package com.itheima.file.controller;

import com.itheima.file.util.HTTPHelper;
import dm.jdbc.filter.stat.json.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Base64;
import java.util.LinkedHashMap;

@Slf4j
@RestController
@RequestMapping("/api")
public class ApiController {

    @GetMapping("/test")
    public String test(){

        JSONObject reqBodyObj = new JSONObject();
        reqBodyObj.put("app_id", "hcmcloud");
        reqBodyObj.put("table_name", "");
        reqBodyObj.put("stringDate", "20210301");
        reqBodyObj.put("condition", "1=1");
        reqBodyObj.put("secretKey", "f3ac852124d2f991a3f63f2e33dae18b");

        LinkedHashMap<String, String> header = new LinkedHashMap<String, String>();
        header.put("username", "po_soap1");
        header.put("password", "z123456789");
        header.put("Authorization", "Basic "+ Base64.getUrlEncoder().encodeToString(("po_soap1" + ":" + "z123456789").getBytes()));
        String postUrl = "https://podev.minmetals.com.cn:50001/RESTAdapter/BS_OA/BS_MDM/DeleteAssHrtree";
        try {
            String result = HTTPHelper.sendPOST(postUrl, reqBodyObj.toString(), header, "UTF-8");
            System.out.println(result);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return "";
    }
}
